Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
It helps to know why you got an error.
First, require me where you could throw errors:
import YError from 'yerror';
Then, emit errors with a bonus: parameters!
function doSomething(pay, action) {
if(parseInt(pay, 10) !== pay) {
throw new YError('E_BAD_PAY', pay, action);
}
}
doSomething('nuts', 'code');
// YError: E_BAD_PAY (nuts, code)
// at doSomething (/home/nfroidure/nfroidure/yerror/test.js:5:11)
// at Object.<anonymous> (/home/nfroidure/nfroidure/yerror/test.js:9:1)
// (...)
You don't have to use constant like error messages, we use this convention mainly for i18n reasons.
Also, you could want to wrap errors and keep a valuable stack trace:
function doSomethingAsync(pay, action) {
return new Promise(function(resolve, reject) {
try {
doSomething(pay, action);
resolve();
} catch(err) {
reject(YError.bump(err));
}
});
}
doSomethingAsync('nuts', 'code')
.catch(function(err) {
console.log(err.stack);
});
// YError: E_BAD_PAY (nuts, code)
// at doSomething (/home/nfroidure/nfroidure/yerror/test.js:5:11)
// (...)
// YError: E_BAD_TRANSACTION (pay)
// at Function.YError.wrap (/home/nfroidure/nfroidure/yerror/src/index.js:41:12)
// at /home/nfroidure/nfroidure/yerror/test.js:16:21
// at doSomethingAsync (/home/nfroidure/nfroidure/yerror/test.js:11:11)
// (...)
Error
An YError class able to contain some params and print better stack traces
string
Allow to print a stack from anything (especially catched errors that may or may not contain errors 🤷).
Error
An YError class able to contain some params and print better stack traces
Kind: global class
Extends: Error
Error
Creates a new YError with an error code and some params as debug values.
Param | Type | Default | Description |
---|---|---|---|
[errorCode] | string | "'E_UNEXPECTED'" | The error code corresponding to the actual error |
[...params] | any | Some additional debugging values |
YError
Wraps any error and output a YError with an error code and some params as debug values.
Kind: static method of YError
Returns: YError
- The wrapped error
Param | Type | Default | Description |
---|---|---|---|
err | Error | The error to wrap | |
[errorCode] | string | "'E_UNEXPECTED'" | The error code corresponding to the actual error |
[...params] | any | Some additional debugging values |
YError
Return a YError as is or wraps any other error and output a YError with a code and some params as debug values.
Kind: static method of YError
Returns: YError
- The wrapped error
Param | Type | Default | Description |
---|---|---|---|
err | Error | The error to cast | |
[errorCode] | string | "'E_UNEXPECTED'" | The error code corresponding to the actual error |
[...params] | any | Some additional debugging values |
YError
Same than YError.wrap()
but preserves the code
and the debug values of the error if it is
already an instance of the YError constructor.
Kind: static method of YError
Returns: YError
- The wrapped error
Param | Type | Default | Description |
---|---|---|---|
err | Error | The error to bump | |
[errorCode] | string | "'E_UNEXPECTED'" | The error code corresponding to the actual error |
[...params] | any | Some additional debugging values |
string
Allow to print a stack from anything (especially catched errors that may or may not contain errors 🤷).
Kind: global function
Returns: string
- The stack trace if any
Param | Type | Description |
---|---|---|
err | Error | The error to print |
FAQs
It helps to know why you got an error.
The npm package yerror receives a total of 15,548 weekly downloads. As such, yerror popularity was classified as popular.
We found that yerror demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.